Skip to content

Accept abbreviated long options in rfl::cli - #27

Open
clockblocker wants to merge 1 commit into
wave-base-7from
cli-abbreviated-long-options
Open

clockblocker wants to merge 1 commit into
wave-base-7from
cli-abbreviated-long-options

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the opt-in rfl::cli::AllowAbbreviations processor so unambiguous prefixes of long options resolve automatically (e.g. --verb → --verbose), without changing default rfl::cli::read behavior.

Example

struct Database { std::optional<std::string> host; std::optional<int> port; };
struct Config {
  std::optional<bool> verbose;
  std::optional<bool> force_export;
  std::optional<std::string> format;
  std::optional<Database> database;
};

// Unique prefix resolves (including nested leaf names and SeparateOptionValues):
rfl::cli::read<Config, rfl::cli::AllowAbbreviations>({"--verb", "--database.h=db.local"});
// -> verbose=true, database={host="db.local"}

// Ambiguous prefix fails (with or without NoExtraFields):
rfl::cli::read<Config, rfl::cli::AllowAbbreviations>({"--for"});
// -> error: Option '--for' is ambiguous; possibilities: '--force-export', '--format'.

Key details

  • Exact matches always win over longer names with the same prefix.
  • In dotted names only the final segment abbreviates (--database.h, not --data.host); map keys, rfl::ExtraFields keys, and short options are never abbreviated.
  • Works with rfl::NoExtraFields, rfl::cli::SeparateOptionValues, and the two-step parse_argv + resolve_args API. Ignored by non-CLI formats.
  • Docs updated in cli.md ("Abbreviated long options").

Open question: keep opt-in (rfl::cli::AllowAbbreviations) or enable by default (like getopt_long/argparse)?

AI-authored. Depends on: #25.

@clockblocker
clockblocker force-pushed the cli-abbreviated-long-options branch from 911a3b7 to f9cf5e3 Compare November 14, 2026 13:01
@clockblocker
clockblocker changed the base branch from wave-base-5 to wave-base-7 November 14, 2026 13:01
@clockblocker
clockblocker force-pushed the cli-abbreviated-long-options branch 2 times, most recently from 9e31055 to 7a50cf9 Compare November 16, 2026 05:18
@clockblocker
clockblocker force-pushed the cli-abbreviated-long-options branch 3 times, most recently from faa3a7c to dbaccb7 Compare November 17, 2026 07:15
With the new rfl::cli::AllowAbbreviations processor, a long option that
matches no field stands for the one long option it is a prefix of, so
`--rep` is `--report`. Only the last part of a dotted name is shortened
(`--database.h`, not `--data`). An exact match wins, and a prefix of
several options fails with "Option '--for' is ambiguous; possibilities:
'--force-export', '--format'." Short options, map keys and
rfl::ExtraFields keys are never abbreviated.

This is opt-in, like rfl::AllowRawPtrs. Without AllowAbbreviations,
rfl::cli::read behaves as before: a long option that is a prefix of
another is ignored, or rejected with rfl::NoExtraFields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant